package com.yuanye.gwcit.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.yuanye.gwcit.R;

public class NumberKeyAdapter extends BaseAdapter {

    Context context;
    Handler handler;

    public NumberKeyAdapter(Context context, Handler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    public int getCount() {
        return 9;
    }

    @Override
    public Object getItem(int i) {
        return String.valueOf(i+1);
    }

    @Override
    public long getItemId(int i) {
        return i+1;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
//        Button button = (Button) LayoutInflater.from(context).inflate(R.layout.digit_keyboard_item, viewGroup, false); // 加载自定义布局中的按钮项
        Button button = new Button(context);
        button.setText(String.valueOf(i+1)); // 设置按钮文本为对应的数字字符串（例如，0, 1, 2, ...）
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Message msg = Message.obtain();
//                msg.what = 0;
//                msg.obj = i;
                if (handler != null) handler.sendEmptyMessage(i);
            }
        });
        return button; // 返回按钮项视图
    }
}
